// 类的泛型支持
class SimpleSet<T> { 
  private elements: Map<T, boolean>;
  constructor(initialElements: T[] = []) { 
    this.elements = new Map<T, boolean>;
    initialElements.forEach(element => this.add(element));
  }

  add(element: T): this { 
    this.elements.set(element, true);
    return this;
  }

  has(element: T): boolean { 
    return this.elements.has(element);
  }

  delete(element: T): boolean { 
    return this.elements.delete(element);
  }

  values(): T[] { 
    return Array.from(this.elements.keys());
  }

  static of<E>(...elements: E[]): SimpleSet<E>{
    const set = new SimpleSet<E>();
    elements.forEach(element => set.add(element));
    return set;
  }
}

class MutableSet<T> extends SimpleSet<T>{
  // add(element: T): this { 
  //   super.add(element);
  //   return this;
  // }
  show() {
    console.log("Mutable Show");
  }
}


const mySet1 = new SimpleSet<number>();
mySet1.add(1).add(2).add(3); // 链式调用

console.log(mySet1.values());

mySet1.delete(2);
console.log(mySet1.values());

const mySet2 = new SimpleSet(["a", "b", "c"]);
console.log(mySet2.values());

const mySet3 = SimpleSet.of(100, 200, 300);
console.log(mySet3.values())

